I have a bool[,] in F# and I want to get the count of true 's present. How can i do this without descending into imperative programming?
this is my current solution, which is really just c# written in f#.
let mutable x = 0
for cell in cells do
if cell = true then x <- x + 1
x
MisterMetaphor :
Here's one way:\n\nlet x = cells |> Seq.cast |> Seq.filter id |> Seq.length\n\n\nWhat it does is filters out false values (see Seq.filter), and then just counts what's left.",
2014-08-01T06:26:17